<?php

if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
loadcache('plugin');
if(!defined('Adz_class')){include('Adz.class.php');}
include_once('acan_open.fun.php');

function Afun_json($data){
	//输出JSON字符串
	ob_end_clean();ob_start();
	header("Access-Control-Allow-Origin: *");
	header('Content-type: application/json; charset=UTF-8');
	if(is_string($data)){
		echo $data;
	}else{
		echo json_encode($data);
	}
	exit;
}
$openOpt = $_G['cache']['plugin']['acan_open'];
if($_GET['op']=='login'){
	$url=AcanOpenGetHost()."qrcode/create_login?key=".$openOpt['key'].'&token='.getToken().'&sid='.$_GET['sid'];
}elseif($_GET['op']=='relogin'){
	$url=AcanOpenGetHost()."qrcode/create_relogin?key=".$openOpt['key'].'&token='.getToken().'&sid='.$_GET['sid'].'&uid='.$_G['uid'];
}elseif($_GET['op']=='bind'){
	$url=AcanOpenGetHost()."qrcode/create_bind?key=".$openOpt['key'].'&token='.getToken().'&sid='.$_GET['sid'].'&uid='.$_G['uid'].'&nickname='.$_G['username'];
}elseif($_GET['op']=='login_auth'){
	$url=AcanOpenGetHost()."qrcode/login_auth?key=".$openOpt['key'].'&token='.getToken().'&hash='.$_GET['hash'];
}
$rs=Adz::curl('get',$url,'',1);
// 登录
if($_GET['op']=='login_auth'){
	include template('common/header_ajax');
	$json = json_decode($rs['data']);
	if($json->uid && $json->key === $openOpt['key']){
		connect_login($json->uid);
		manageaftlogin($json->uid); //login extra
	}
}
Afun_json($rs['data']);

?>